//
//  SISSHouseLayoutDrawingView.m
//  SISSAPP
//
//  Created by 袁应荣 on 2018/10/18.
//  Copyright © 2018年 优房网. All rights reserved.
//

#import "SISSHouseLayoutDrawingView.h"
#import "SISSBaseCollectionView.h"
#import "SISSHouseLayoutDrawingCollectionViewCell.h"

@interface SISSHouseLayoutDrawingView ()<UICollectionViewDelegate,UICollectionViewDataSource>

@property (weak, nonatomic) UILabel *titleLabel;
@property (weak, nonatomic) UIButton *moreButton;
@property (weak, nonatomic) SISSBaseCollectionView *collectionView;

@end
@implementation SISSHouseLayoutDrawingView

- (void)moreButtonClickAction {

    if ([self.delegate respondsToSelector:@selector(moreButtonClickAction)]) {
        [self.delegate moreButtonClickAction];
    }
}

#pragma mark - UICollectionViewDataSource & UICollectionViewDelegate

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 10;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    SISSHouseLayoutDrawingCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:houseLayoutDrawingCollectionViewCellReuseID forIndexPath:indexPath];
    
    return cell;
}



- (void)initUI {
    [super initUI];
    
    UILabel *titleLabel = [UILabel yyr_labelWithText:@"户型图" fontSize:18 textColor:MAIN_TEXT_COLOR];
    [self addSubview:titleLabel];
    self.titleLabel = titleLabel;
    
    UIButton *moreButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [moreButton setTitleColor:SECONDARY_TEXT_COLOR forState:UIControlStateNormal];
    [moreButton setTitle:@"更多>" forState:UIControlStateNormal];
    moreButton.titleLabel.font = [UIFont systemFontOfSize:15];
//    [moreButton setImage:[UIImage imageNamed:@"more"] forState:UIControlStateNormal];
    [moreButton addTarget:self action:@selector(moreButtonClickAction) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:moreButton];
    self.moreButton = moreButton;
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    flowLayout.minimumLineSpacing = 16;
    flowLayout.minimumInteritemSpacing = 0;
    CGFloat itemW = (SCREEN_WIDTH - 3 * 16) / 3;
    flowLayout.itemSize = CGSizeMake(itemW, 140);
    flowLayout.sectionInset = UIEdgeInsetsMake(1, 10, 1, 10);
    SISSBaseCollectionView *collectionView = [[SISSBaseCollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
    collectionView.dataSource = self;
    collectionView.delegate = self;
    collectionView.showsHorizontalScrollIndicator = NO;
    [collectionView registerClass:[SISSHouseLayoutDrawingCollectionViewCell class] forCellWithReuseIdentifier:houseLayoutDrawingCollectionViewCellReuseID];
    [self addSubview:collectionView];
    self.collectionView = collectionView;
    
}

- (void)initConstraint {
    [super initConstraint];
    
    WeakSelf
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(weakSelf).offset(2 * globelMargin);
    }];
    
    [self.moreButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(weakSelf.titleLabel);
        make.right.equalTo(weakSelf).offset(-3 * globelMargin);
//        make.width.mas_greaterThanOrEqualTo(6 * globelMargin);
    }];
    
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(weakSelf);
        make.top.equalTo(weakSelf.titleLabel.mas_bottom).offset(2 * globelMargin);
        make.height.mas_equalTo(140);
        make.bottom.equalTo(weakSelf).offset(-2 * globelMargin);
    }];
    
}


@end
